package com.andaily.web.controller.mobile.thing;

import com.andaily.domain.dto.thing.ThingSettingDto;
import com.andaily.service.ThingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * @author Shengzhao Li
 */
@Controller
@RequestMapping("/thing/setting")
public class ThingSettingController {

    @Autowired
    private ThingService thingService;


    @RequestMapping(value = "form", method = RequestMethod.GET)
    public String showForm(Model model) {
        ThingSettingDto thingSettingDto = thingService.loadThingSettingDto();
        model.addAttribute("thingSettingDto", thingSettingDto);
        return "thing/thing_setting_form";
    }

    @RequestMapping(value = "form", method = RequestMethod.POST)
    public String submit(@ModelAttribute("thingSettingDto") ThingSettingDto thingSettingDto, Model model) {
        thingService.updateThingSettingDto(thingSettingDto);
        return "redirect:form?result=true";
    }


}
